package com.example.demo.entity;



import org.springframework.http.HttpStatus;

/**
 *
 * @param <T>
 */
//@ApiModel(value = "返回结果对象", description = "返回结果对象")
public class InvokeResult<T> {

//	@ApiModelProperty(value = "返回结果json", name = "data")
	private T data;

//	@ApiModelProperty(value = "响应信息", name = "message")
	private String message;

//	@ApiModelProperty(value = "响应状态", name = "status")
	private int status;

//	@ApiModelProperty(value = "请求是否有错", name = "hasErrors")
	private boolean hasErrors;


	public InvokeResult(){
		this.status = HttpStatus.OK.value();
		this.hasErrors = false;
	}

    public InvokeResult(T data){
		this.data = data;
		this.status = HttpStatus.OK.value();
		this.hasErrors = false;
	}
//	public InvokeResult(AbstractBusinessException e){
//		this.hasErrors = true;
//		this.message = e.getMessage();
//		this.status  = e.getStatus().value();
//
//	}


	public T getData() {
		return data;
	}

	public String getMessage() {
		return message;
	}

	public boolean isSuccess() {
		return !hasErrors;
	}

	public int getStatus() {
		return status;
	}

    /**
     * 返回的业务数据
     * @param data
     */
	public void setData(T data) {
		this.data = data;
	}

    /**
     * 返回的自定义通知信息
     * @param message
     */
	public void setMessage(String message) {
	    this.message = message;
    }

    /**
     * 是否存在业务逻辑错误
     * @param hasErrors
     */
    public void setHasErrors(boolean hasErrors) {
	    this.hasErrors = hasErrors;
    }

	public boolean getHasErrors() {
		return hasErrors;
	}
}
